package tsif.tcluster.service;

import tsif.tcluster.ITClusterAccessor;
import tsif.tcluster.TClusterContext;
import tsif.tcluster.service.proxy.TClusterServiceProxy;

/** 集群服务接口 **/
public abstract class TClusterService implements ITClusterService {
	protected long serviceId;
	protected TClusterServiceProxy serviceProxy;
	protected TClusterContext context;
	protected ITClusterAccessor accessor;

	@Override
	public boolean init(TClusterServiceProxy serviceProxy, long serviceId, Object... args) throws Exception {
		this.serviceProxy = serviceProxy;
		this.serviceId = serviceId;
		this.context = serviceProxy.getContext();
		this.accessor = serviceProxy.getAccessor();
		return true;
	}

	public long getServiceId() {
		return serviceId;
	}

	/** 获取集群环境 **/
	public TClusterContext getContext() {
		return context;
	}

	/** 获取访问器 **/
	public ITClusterAccessor getAccessor() {
		return accessor;
	}

	/** 获取服务代理 **/
	public TClusterServiceProxy getServiceProxy() {
		return serviceProxy;
	}

	@Override
	public String toString() {
		return this.getClass().getSimpleName() + " []";
	}

}